from pydantic import BaseModel
from typing import List
from datetime import datetime


class CoalRadar(BaseModel):
    id: int
    name: str
    ip: str
    port: int
    axisX: float
    axisY: float
    shiftX: float
    shiftY: float
    shiftZ: float
    rotateX: float
    rotateY: float
    rotateZ: float
    yard_id: int = None
    conn_status: str = 'off'
    data_status: str = 'off'
    bytes_buffer: bytes = bytes()
    callback_time: datetime = None


class HeapPoint(BaseModel):
    x: float
    y: float


class CoalHeap(BaseModel):
    coalHeapId: int
    coalHeapName: str
    coalHeapArea: List[HeapPoint]
    density: float = None
    mesId: int = None


class CoalYard(BaseModel):
    coalYardId: int
    coalYardName: str
    coalRadarList: List[CoalRadar] = None
    coalHeapList: List[CoalHeap] = None
    conn_radarsBucket: list = []
    data_status: str = 'off'
    cloud_list: list = []


# class CoalYard(object):
#     def __init__(self, d):
#         for a, b in d.items():
#             if isinstance(b, (list, tuple)):
#                 setattr(self, a, [CoalYard(x) if isinstance(x, dict) else x for x in b])
#             else:
#                 setattr(self, a, CoalYard(b) if isinstance(b, dict) else b)
#
#     @property
#     def coalYardId(self):
#         return self.coalYardId
#
#     @coalYardId.setter
#     def coalYardId(self, yard_id):
#         self.coalYardId = yard_id


class InventoryCoalResult:
    coalHeapId: int
    coalHeapName: str
    volume: float
    maxHeight: float
    cloudInfo: str
    density: float = None
    mesId: int = None
    bytes_buffer: bytes
